package org.example.tlias.controller;

import org.example.tlias.pojo.Clazz;
import org.example.tlias.pojo.ClazzQueryParam;
import org.example.tlias.pojo.PageResult;
import org.example.tlias.pojo.Result;
import org.example.tlias.services.ClazzsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzsController {
    @Autowired
    private ClazzsService clazzsService;

    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam){
       PageResult<Clazz> pageResult = clazzsService.page(clazzQueryParam);
       return Result.success(pageResult);
    }

    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        clazzsService.save(clazz);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzsService.deleteById(id);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Clazz clazz = clazzsService.getById(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzsService.update(clazz);
        return Result.success();
    }
    @GetMapping("list")
    public Result list(){
        return Result.success(clazzsService.list());
    }


}
